package com.constant
{
	/**
	 * @author lijia
	 */	
	public class ProtoAttrType
	{
		public function ProtoAttrType()
		{
		}

		public static const BYTE_TYPE:String = "byte";
		public static const BOOLEAN_TYPE:String = "bool";
		public static const SHORT_TYPE:String = "short";
		public static const USHORT_TYPE:String = "ushort";
		public static const INT_TYPE:String = "int";
		public static const UINT_TYPE:String = "uint";
		public static const FLOAT_TYPE:String = "float";
		public static const LONG_TYPE:String = "long";
		public static const ULONG_TYPE:String = "ulong";
		public static const STRING_TYPE:String = "string";
		public static const ARRAY_TYPE:String = "array";

		private static const protoTypeMap:Object = 
		{
			"cshap" : {
				"byte" : ["byte", "Byte", "Byte"]
				,"short" : ["short", "Short", "Short"]
				,"ushort" : ["ushort", "UShort", "UShort"]
				,"int" : ["int", "Int", "Int"]
				,"uint" : ["uint", "UInt", "UInt"]
				,"float" : ["float", "Float", "Float"]
				,"long":["ulong", "ULong", "ULong"]
				,"ulong":["ulong", "ULong", "ULong"]
				,"string":["string", "String", "String"]
			},
			"lua":{
				"byte":["C"]
				,"short":["h"]
				,"ushort" : ["H"]
				,"int":["i"]
				,"uint":["I"]
				,"float" : ["f"]
				,"long":["L"]
				,"ulong":["L"]
				,"string":["s"]
			}
		}

		public static function getProtoType(lang:String, type:String):String{
			var map:Object = ProtoAttrType.protoTypeMap[lang];
			if(map.hasOwnProperty(type)){
				return map[type][0];
			}
			return type;
		}
		
		public static function getProtoRead(lang:String, type:String):String{
			var map:Object = ProtoAttrType.protoTypeMap[lang];
			if(map.hasOwnProperty(type)){
				return map[type][1];
			}
			throw new Error(lang+"语言找不到"+type+"类型的read方法");
			return type;
		}
		
		public static function getProtoWrite(lang:String, type:String):String{
			var map:Object = ProtoAttrType.protoTypeMap[lang];
			if(map.hasOwnProperty(type)){
				return map[type][2];
			}
			throw new Error(lang+"语言找不到"+type+"类型的write方法");
			return type;
		}
		
		
	}
}